package com.kaifamiao.io.d0921;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;

public class BufferedOutputStreamDemo {

    public static void main(String[] args) {
        String path = "d:\\io\\buffer-output.txt";
        try (FileOutputStream fos = new FileOutputStream(path);
             BufferedOutputStream bos = new BufferedOutputStream(fos);){
            Charset charset = Charset.forName("UTF-8");

            String s = "中国智造惠及全球";

            byte[] bytes = s.getBytes(charset); // 使用 charset 将 字符串 编码 为 字节序列

            bos.write(bytes); // 将 bytes 数组中的所有字节 写入到 bos 对应的流内部的 缓冲区中

            /*
               1 KB = 1024 B
               1 MB = 1024 KB
               1 GB = 1024 MB
               1 TB = 1024 GB
             */

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
